const birdDom = document.querySelector(".bird");
const gameDom = document.querySelector(".game");
const birdStyle = getComputedStyle(birdDom);
const birdWidth = parseFloat(birdStyle.width);
const birdHeight = parseFloat(birdStyle.height);
const birdLeft = parseFloat(birdStyle.left);
const birdTop = parseFloat(birdStyle.top);
const gameHeight = parseFloat(getComputedStyle(gameDom).height)

class Bird extends dad{
    constructor (){
        super(birdHeight, birdWidth, birdLeft, birdTop, 0, 0, birdDom)
        this.g = 1500;
        this.maxY = gameHeight - landHeight - birdHeight;
        this.SW = 1;//小鸟的翅膀状态
        this.timer = null;//翅膀扇动计时器
        this.render();
    }

    starSW(){
        if (this.timer){
            return;
        }
        this.timer = setInterval(() => {
            this.SW++;
            if(this.SW === 4){
                this.SW = 1;
            }
            this.render();
        }, 300);
    }

    render() {
        super.render();
        this.dom.className = `swing${this.SW} `;
    } 
    stopSW(){
        clearInterval(this.timer)
        this.timer = null;
    }


    move(atime){
        super.move(atime);
        this.yspeed += this.g * atime ;
    }

    onMove(){
        if(this.top < 0){
            this.top = 0;
        }else if (this.top > this.maxY ){
            this.top = this.maxY;
        }
    }

    jump(){
        this.yspeed = -500;
    }

 

}

//赵嘉鹏